package com.kwin.reqexcel;

import com.kwin.reqexcel.filter.ReuqestExcelArgumentResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : wangkai
 * @version V1.0
 * @Package com.kwin.reqexcel
 * @Description:
 * @date 2021年10月19日 13:50
 **/
@RequiredArgsConstructor
@Configuration
public class ExcelHandlerConfiguration {
    
    private final RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    
    
    /**
     * 追加 Excel 请求处理器 到 springmvc 中
     */
    @PostConstruct
    public void addRequestExcelArgumentResolver() {
        List<HandlerMethodArgumentResolver> argumentResolvers = requestMappingHandlerAdapter.getArgumentResolvers();
        List<HandlerMethodArgumentResolver> resolverList = new ArrayList<>();
        resolverList.add(new ReuqestExcelArgumentResolver());
        resolverList.addAll(argumentResolvers);
        requestMappingHandlerAdapter.setArgumentResolvers(resolverList);
    }
}
